/*
 * XAppFrame.java, created on Oct 21, 2005
 * 
 * Copyright (c) 2005 - 2007
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.xfc;

import java.awt.Container;

import javax.swing.JPanel;
import javax.swing.JToolBar;

import org.xfc.components.XFrame;
import org.xfc.components.XStatusBar;

import com.jgoodies.forms.layout.FormLayout;

/**
 * A main window for an XApp. In most applications there will only ever be one XAppFrame
 * created.
 * 
 * @author Devon Carew
 */
public class XAppFrame
	extends XFrame
{
	protected XStatusBar 	statusBar;
	
	// TODO: This should be a XToolBarArea
	protected JToolBar 		toolBar;
	
	protected JPanel		frameContent;
	
	/**
	 * @param app
	 */
	public XAppFrame(XApp app)
	{
		super(app);
		
		super.getContentPane().setLayout(new FormLayout(
			"4dlu, fill:default:grow, 4dlu",
			//"pref, 4dlu, fill:default:grow, 4dlu, pref"
			"pref, 0dlu, fill:default:grow, 0dlu, pref"
		));
		
		// TODO: configurable has status bar
		
		
		
		setStatusBar(new XStatusBar(app));
		
		frameContent = new JPanel();
		
		super.getContentPane().add(frameContent, "1, 3, 3, 1");
	}
	
	/** 
	 * @return Container
	 * @see javax.swing.RootPaneContainer#getContentPane()
	 */
	public Container getContentPane()
	{
		return getFrameContent();
	}
	
	/**
	 * @return Returns the frameContent.
	 */
	public JPanel getFrameContent()
	{
		return frameContent;
	}
	
	/**
	 * @return the XApp owner of this XAppFrame
	 */
	public XApp getApp()
	{
		return app;
	}
	
	/**
	 * @return Returns the statusBar.
	 */
	public XStatusBar getStatusBar()
	{
		return statusBar;
	}
	
	/**
	 * @param statusBar The statusBar to set.
	 */
	public void setStatusBar(XStatusBar statusBar)
	{
		if (statusBar != null)
			super.getContentPane().remove(statusBar);
		
		this.statusBar = statusBar;
		
		if (statusBar != null)
			super.getContentPane().add(statusBar, "1, 5, 3, 1");
	}
	
	/**
	 * @return Returns the toolBar.
	 */
	public JToolBar getToolBar()
	{
		return toolBar;
	}
	
	/**
	 * @param toolBar The toolBar to set.
	 */
	public void setToolBar(JToolBar toolBar)
	{
		if (toolBar != null)
			super.getContentPane().remove(toolBar);
		
		this.toolBar = toolBar;
		
		if (toolBar != null)
			super.getContentPane().add(toolBar, "1, 1, 3, 1, f, c");
	}
	
}
